<div id="deviceMonitoingGridbox" style="width:100%;height:100%;background-color:white;overflow:hidden;border-top: none;border-left: none;"></div>
<script>
var devMonitorGrid = new dhtmlXGridObject('deviceMonitoingGridbox');
var isInitDevMonitor = true;
var devMonitorTimeout = null;
var devMonitorClientId = "devMonitor"+new Date().getTime();

// devMonitorGrid.setImagePath("../../../codebase/imgs/");
devMonitorGrid.setHeader("设备名称,设备序列号,设备IP,当前状态,通信端口");
devMonitorGrid.setInitWidths("100,100,100,100,*");
devMonitorGrid.setColAlign("left,left,left,left,left");
devMonitorGrid.setColTypes("ro,ro,ro,ro,ro");
devMonitorGrid.setColSorting("str,str,str,str,str");
devMonitorGrid.init();
// devMonitorGrid.load("device.do?devMonitoring","json");
refreshMonitoringData();


function refreshMonitoringData() {
	var url = "device.do?devMonitoring&clientId="+devMonitorClientId;
	$.ajax({
        type: "GET",
        url: url,
        dataType: "json",
        async: true,
        success: function(dataObj)
        {
        	var length = dataObj.rows.length;
   			if(isInitDevMonitor)//初始化
            {
   				devMonitorGrid.clearAll();//清除原来的数据
   				devMonitorGrid.enableSmartRendering(dataObj.rows.length > 1000 ? true : false);
            }
   			
   			if(length > 0)
   			{
   				for(var i=0;i<length;i++)
                {
   					var id = dataObj.rows[i].id;
   					if(devMonitorGrid.doesRowExist(id))//判断是否存在该id（修改）
					{
//    						printLog("修改"+id);
                    	for(var k = 0; k < devMonitorGrid.getColumnsNum(); k++)
                    	{
                    		devMonitorGrid.cells(id, k).setValue(dataObj.rows[i].data[k]);
                    	}
                    	devMonitorGrid.setRowTextStyle(id, dataObj.rows[i].style);
                    }
                    else//新增
                    {
                    	printLog('新增'+id);
                    	devMonitorGrid.addRow(id, dataObj.rows[i].data);
                    	devMonitorGrid.setRowTextStyle(id, dataObj.rows[i].style);
                    }	
   					
                }
   			}
   			devMonitorTimeoutFun();
		},
        error:function (XMLHttpRequest, textStatus, errorThrown)
 		{
			window.clearTimeout(devMonitorTimeout);
       	}
    });
}

//监控定时循环
function devMonitorTimeoutFun()
{
	devMonitorGrid.setSizes(false);
	window.clearTimeout(devMonitorTimeout);
	devMonitorTimeout = setTimeout("refreshMonitoringData()", 2000);
	isInitDevMonitor = false;
}
</script>